//
// Created by Jisam on 2024/6/27.
//
#include "queue"
#include "iostream"
#define i64 long long
using namespace  std;
int a,b;
const int maxn = 1e5 + 10 ;
int f[maxn]={0};

int main(){
    scanf("%d%d",&a,&b);
    queue<int> q;

    q.push(a);

    while(!q.empty()){
        int t = q.front();
        q.pop();
        if(t == b) {
            printf("%d",f[t]);
            return 0;
        }
        if(t - 1 >= 0 && !f[t - 1]  ){
            f[t-1]  = f[t] +1;
            q.push(t-1);
        }
        if(t + 1 <= maxn && !f[t + 1 ] ){
            f[t+1]  = f[t] +1;
            q.push(t+1);
        }
        if( t <<1 <= maxn  && !f[t << 1]){
            f[t << 1]  = f[t] +1;
            q.push(t << 1);
        }
    }
    return  0;
}